<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row>
          <el-button type="success" @click="handleCreate">&emsp;新增&emsp;</el-button>
          <!-- <el-button type="danger" @click="handleDeleteAll">批量删除</el-button> -->
          <el-form ref="listQuery" :inline="true" :model="listQuery" class="demo-form-inline">
            <el-form-item label="">
              <el-input v-model="listQuery.id" placeholder="道具包ID" type="text"></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="listQuery.name" placeholder="道具包名称" type="text"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="searchSubmit">查询</el-button>
              <el-button type="primary" @click="resetSubmit">重置</el-button>
            </el-form-item>
          </el-form>
        </el-row>
      </div>
      <div v-loading="listLoading" class="item">
        <el-table ref="dataList" :data="menuList" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                  border row-key="id"
                  style="width:100%;margin-bottom: 20px;"
        >
          <!-- <el-table-column type="selection"></el-table-column> -->
          <el-table-column label="序号" prop="id"></el-table-column>
          <el-table-column label="道具包类型" prop="type">
            <template slot-scope="scoped">
              <p v-if="scoped.row.type === 1">普通道具包</p>
              <p v-if="scoped.row.type === 2">特殊道具包</p>
            </template>
          </el-table-column>
          <el-table-column label="道具包名称" prop="name"></el-table-column>
          <el-table-column label="道具包说明" prop="remark">
            <template slot-scope="scoped">
              <p v-if="scoped.row.remark !== 0">{{ scoped.row.remark }}</p>
              <p v-else></p>
            </template>
          </el-table-column>
          <el-table-column label="道具包图片" prop="picture">
            <template slot-scope="scope">
              <el-popover max-width="420" placement="right" trigger="hover">
                <img :src="scope.row.picture" alt="" style="max-width: 200px;max-height: 200px">
                <img slot="reference" :src="scope.row.picture" alt="" style="width: 50px;">
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column label="道具包内容" prop="reward_detail" width="230">
            <template slot-scope="scope">
              <div v-if="scope.row.reward_detail !== []" style="display:flex;flex-direction:column;">
                <div v-for="(item,index) in scope.row.reward_detail" :key="index" style="margin:5px;">
                  <div v-if="item.reward_item">
                    <div v-if="item.reward_item['item_type'] === 4">
                      <el-tag type="primary">{{ item.reward_item.item_name }}✖{{ item.number }}个</el-tag>
                      <el-tag v-if="item.ratio" type="info">{{ item.ratio }}%</el-tag>
                    </div>
                    <div v-else-if="item.reward_item['item_type'] === 3">
                      <el-tag type="primary">{{ item.reward_item.item_name }}✖{{ item.number }}天</el-tag>
                      <el-tag v-if="item.ratio" type="info">{{ item.ratio }}%</el-tag>
                    </div>
                    <div v-else-if="item.reward_item['item_type'] === 2">
                      <el-tag type="primary">{{ item.reward_item.item_name }}✖{{ item.number }}天</el-tag>
                      <el-tag v-if="item.ratio" type="info">{{ item.ratio }}%</el-tag>
                    </div>
                    <div v-else-if="item.reward_item['item_type'] === 6">
                      <el-tag type="primary">{{ item.reward_item.item_name }}✖{{ item.number }}天</el-tag>
                      <el-tag v-if="item.ratio" type="info">{{ item.ratio }}%</el-tag>
                    </div>
                    <div v-else>
                      <el-tag type="warning">{{ item.reward_item.item_name }}✖{{ item.number }}</el-tag>
                      <el-tag v-if="item.ratio" type="info">{{ item.ratio }}%</el-tag>
                    </div>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="添加时间" prop="created_at"></el-table-column>
          <el-table-column label="操作" width="260px">
            <template slot-scope="scope">
              <el-button icon="el-icon-present" plain size="mini" type="warning" @click="handleGive(scope.row)">赠送
              </el-button>
              <el-button icon="el-icon-edit" plain size="mini" type="primary" @click="handleUpdate(scope.row)">编辑
              </el-button>
              <el-button icon="el-icon-delete" plain size="mini" type="danger" @click="handleDelete(scope.row)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <cus-pagination
          :limit.sync="listQuery.perPage"
          :page.sync="listQuery.page"
          :total="total"
          @pagination="getList"
        />
      </div>
    </el-card>
    <!-- 删除弹框 -->
    <el-dialog
      :visible.sync="deleteDialogVisible"
      title="确定删除吗?"
      width="435px"
    >
      <span style=""><em style="font-style:normal;color:red">删除后不可恢复</em>，你还要继续吗？</span>
      <span slot="footer" class="dialog-footer">
            <el-button @click="deleteDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="confirmDelete">确 定</el-button>
        </span>
    </el-dialog>
    <!-- 新增编辑弹框 -->
    <el-dialog v-dialogDrag :title="titleMap[dialogStatus]" :visible.sync="dialogFormVisible"
               @close="handleDialogClose('editRulesForm')"
    >
      <el-form ref="editRulesForm" :model="editRulesForm" :rules="editRulesFormRules" class="demo-ruleForm"
               label-width="100px"
      >
        <el-form-item label="道具包名称" prop="name">
          <el-input v-model="editRulesForm.name" clearable placeholder="请输入道具包名称"></el-input>
        </el-form-item>
        <el-form-item label="道具包类型" prop="propType">
          <el-radio-group v-model="editRulesForm.propType">
            <el-radio :label="1">普通道具包</el-radio>
            <el-radio :label="2">特殊道具包</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="道具包说明" prop="remark">
          <el-input v-model="editRulesForm.remark" clearable type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="道具包图片" prop="picture">
          <el-upload
            ref="upload"
            :auto-upload="true"
            :file-list="propPictureList"

            :on-change="handleChangePic"
            :on-remove="handlePropPictureRemove"
            :on-success="handlePropPictureSuccess"
            action=""
            class="upload-demo"
            list-type="picture"
          >
            <el-button slot="trigger" size="small" type="primary">上传道具包图片</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item
          v-for="(item, index) in giftArr"
          :key="'礼物'+index"
          label="礼物"
        >
          <el-select v-model="item.item_id" filterable placeholder="请选择礼物" style="margin-bottom:20px">
            <el-option
              v-for="item in giftType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input v-model.number="item.number" clearable placeholder="请输入礼物数量" style="margin-bottom:20px"></el-input>
          <el-input v-if="editRulesForm.propType === 2" v-model.number="item.weight" clearable placeholder="请输入权重"
                    style="margin-bottom:20px"
          ></el-input>
          <el-button @click.prevent="removeGift(item)">删除</el-button>
        </el-form-item>
        <el-form-item
          v-for="(item, index) in mountArr"
          :key="'坐骑'+index"
          label="坐骑"
        >
          <el-select v-model="item.item_id" filterable placeholder="请选择坐骑" style="margin-bottom:20px">
            <el-option
              v-for="item in mountType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input v-model.number="item.number" clearable placeholder="请输入坐骑天数" style="margin-bottom:20px"></el-input>
          <el-input v-if="editRulesForm.propType === 2" v-model.number="item.weight" clearable placeholder="请输入权重"
                    style="margin-bottom:20px"
          ></el-input>
          <el-button @click.prevent="removeMount(item)">删除</el-button>
        </el-form-item>
        <el-form-item
          v-for="(item, index) in pendantArr"
          :key="'挂件'+index"
          label="挂件"
        >
          <el-select v-model="item.item_id" filterable placeholder="请选择挂件" style="margin-bottom:20px">
            <el-option
              v-for="item in pendantType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input v-model.number="item.number" clearable placeholder="请输入挂件天数" style="margin-bottom:20px"></el-input>
          <el-input v-if="editRulesForm.propType === 2" v-model.number="item.weight" clearable placeholder="请输入权重"
                    style="margin-bottom:20px"
          ></el-input>
          <el-button @click.prevent="removePendant(item)">删除</el-button>
        </el-form-item>
        <el-form-item
          v-for="(item, index) in specialArr"
          :key="'特效'+index"
          label="特效"
        >
          <el-select v-model="item.item_id" filterable placeholder="请选择特效" style="margin-bottom:20px">
            <el-option
              v-for="item in specialType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input v-model.number="item.number" clearable placeholder="请输入特效天数" style="margin-bottom:20px"></el-input>
          <el-input v-if="editRulesForm.propType === 2" v-model.number="item.weight" clearable placeholder="请输入比例权重"
                    style="margin-bottom:20px"
          ></el-input>
          <el-button @click.prevent="removeSpecial(item)">删除</el-button>
        </el-form-item>
        <el-form-item
          v-for="(item, index) in propArr"
          :key="'道具'+index"
          label="道具"
        >
          <el-select v-model="item.item_id" filterable placeholder="请选择道具" style="margin-bottom:20px">
            <el-option
              v-for="item in propItemType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input v-model.number="item.number" clearable placeholder="请输入道具数量" style="margin-bottom:20px"></el-input>
          <el-input v-if="editRulesForm.propType === 2" v-model.number="item.weight" clearable placeholder="请输入权重"
                    style="margin-bottom:20px"
          ></el-input>
          <el-button @click.prevent="removeProp(item)">删除</el-button>
        </el-form-item>
        <el-form-item>
          <el-row>
            <el-col :span="5">
              <el-button type="primary" @click="addGift">+礼物</el-button>
            </el-col>
            <el-col :span="5">
              <el-button type="primary" @click="addMount">+坐骑</el-button>
            </el-col>
            <el-col :span="5">
              <el-button type="primary" @click="addPendant">+挂件</el-button>
            </el-col>
            <el-col :span="5">
              <el-button type="primary" @click="addSpecial">+特效</el-button>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="addProp">+道具</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item>
          <el-button @click="dialogFormVisible = false">返回</el-button>
          <el-button type="primary" @click="submitForm('editRulesForm')">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 赠送弹框 -->
    <el-dialog v-dialogDrag :visible.sync="giveFormVisible" title="赠送" @close="handleDialogClose('giveForm')">
      <el-form ref="giveForm" :model="giveForm" :rules="giveFormRules" class="demo-ruleForm" label-width="120px">
        <el-form-item label="道具名称">
          <el-input v-model="giveForm.name" disabled placeholder="请输入名称"></el-input>
        </el-form-item>
        <!-- <el-form-item label="道具类型" prop="propType">
            <el-radio-group v-model="giveForm.propType" disabled>
                <el-radio :label="1">普通道具</el-radio>
                <el-radio :label="2">特殊道具</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="道具说明" prop="remark">
            <el-input disabled type="textarea" v-model="giveForm.remark"></el-input>
        </el-form-item>
        <el-form-item label="道具图片" prop="picture">
            <img :src="giveForm.picture" alt="" style="height:100px">
        </el-form-item>
        <el-form-item label="金币" >
            <el-input v-model="giveForm.gold" style="width:200px;" disabled ></el-input>
            <el-input v-if="giveForm.propType === 2" v-model="giveForm.goldWeight" style="width:200px;" disabled ></el-input>
        </el-form-item>
        <el-form-item label="积分" >
            <el-input v-model="giveForm.gold" style="width:200px;" disabled ></el-input>
            <el-input v-if="giveForm.propType === 2" v-model="giveForm.pointWeight" style="width:200px;" disabled ></el-input>
        </el-form-item>
        <el-form-item
            v-for="(item, index) in giveForm.giftArr"
            label="礼物"
            :key="'礼物'+index"
        >
            <el-select filterable v-model="item.item_id" placeholder="请选择礼物" disabled style="margin-bottom:20px">
                <el-option
                v-for="item in giftType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            <el-input v-model.number="item.number" placeholder="请输入礼物数量" disabled style="margin-bottom:20px"></el-input>
            <el-input v-model.number="item.weight" placeholder="请输入比例权重" disabled style="margin-bottom:20px"></el-input>
        </el-form-item>
        <el-form-item
            v-for="(item, index) in giveForm.mountArr"
            label="坐骑"
            :key="'坐骑'+index"
        >
            <el-select filterable v-model="item.item_id" placeholder="请选择坐骑" disabled style="margin-bottom:20px">
                <el-option
                v-for="item in mountType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            <el-input v-model.number="item.number" placeholder="请输入坐骑天数" disabled style="margin-bottom:20px"></el-input>
            <el-input v-model.number="item.weight" placeholder="请输入比例权重" disabled style="margin-bottom:20px"></el-input>
        </el-form-item>
        <el-form-item
            v-for="(item, index) in giveForm.pendantArr"
            label="挂件"
            :key="'挂件'+index"
        >
            <el-select filterable v-model="item.item_id" placeholder="请选择挂件" disabled style="margin-bottom:20px">
                <el-option
                v-for="item in pendantType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            <el-input v-model.number="item.number" placeholder="请输入挂件天数" disabled style="margin-bottom:20px"></el-input>
            <el-input v-model.number="item.weight" placeholder="请输入比例权重" disabled style="margin-bottom:20px"></el-input>
        </el-form-item>
        <el-form-item
            v-for="(item, index) in giveForm.specialArr"
            label="特效"
            :key="'特效'+index"
        >
            <el-select filterable v-model="item.item_id" placeholder="请选择特效" disabled style="margin-bottom:20px">
                <el-option
                v-for="item in specialType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            <el-input v-model.number="item.number" placeholder="请输入特效天数" disabled style="margin-bottom:20px"></el-input>
            <el-input v-model.number="item.weight" placeholder="请输入比例权重" disabled style="margin-bottom:20px"></el-input>
        </el-form-item> -->
        <el-form-item label="用户编号" prop="user_codes">
          <el-input v-model="giveForm.user_codes" type="textarea"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="giveFormVisible = false">返回</el-button>
          <el-button type="primary" @click="giveSubmit('giveForm')">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  listData,
  typeData,
  listTypeData,
  listSpecialData,
  listPropData,
  putData,
  putSendData
} from '@/api/prop/propBagList'
import {
  getToken
} from '@/utils/auth'
import { IMG_UPLOAD_URL } from "../../data/basic_data";

export default {
  data() {
    return {

      typeOptions: [],

      giveShowPicture: [],
      giveFormRules: {
        user_code: [{ required: true, message: '请输入用户编号', trigger: 'blur' }]
      },
      giveForm: {
        name: undefined,
        /* propType:1,
        gold:undefined,
        point:undefined,
        goldWeight:undefined,
        pointWeight:undefined,
        remark:undefined,
        picture:undefined,
        status:1,
        giftArr:[],
        mountArr:[],
        pendantArr:[],
        specialArr:[], */
        user_codes: undefined
      },
      giveFormVisible: false,

      // 徽章状态
      badgeStatus: [
        { value: 1, label: '开启' },
        { value: 2, label: '隐藏' },
      ],
      // 要修改的当前行的idsearchSubmit
      row_id: 0,
      // 表单规则
      editRulesFormRules: {
        name: [{ required: true, message: '请输入名称1-30字符', trigger: 'blur', min: 1, max: 30 }],
        sort: [{ required: true, message: '请输入排序数字', trigger: 'blur' }],
        status: [{ required: true, message: '请选择状态', trigger: 'change' }],
      },
      // 图片数组
      propPictureList: [],
      giftType: [],
      mountType: [],
      pendantType: [],
      specialType: [],
      propItemType: [],

      giftArr: [],
      mountArr: [],
      pendantArr: [],
      specialArr: [],
      propArr: [],

      editRulesForm: {
        name: undefined,
        propType: 1,
        remark: undefined,
        picture: undefined,
      },
      dialogStatus: '',
      // dialog的头部信息
      titleMap: {
        update: '编辑',
        create: '新增'
      },
      dialogFormVisible: false,
      deleteDialogVisible: false,
      listLoading: false,
      menuList: [],
      limitList: [],
      listQuery: {
        page: 1,
        perPage: 10,
        id: undefined,
        name: undefined
      },
      total: 0,
      // 勾选内容
      multipleSelection: [],
      // 要删除的内容的ids
      dataIds: '',
      // ids:[],
    }
  },
  created() {
    this.getTypeList()
    this.getList()
    this.getSpecialList()
    this.getTypeData()
    this.getPropList()
  },
  methods: {
    // 监听dialog关闭时的处理事件
    handleDialogClose(formName) {
      if (this.$refs[formName]) {
        this.$refs[formName].clearValidate(); // 清除整个表单的校验
      }
    },
    handleChangePic(fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
    },
    handlePropPictureSuccess(res) {
      this.editRulesForm.picture = res.data.url
      this.propPictureList = [{ url: res.data.url }]
    },
    handlePropPictureRemove(res) {
      this.editRulesForm.picture = undefined;
      this.propPictureList = []
    },
    handleRelease(row) {
      this.row_id = row.id;
      putRelease(this.row_id).then(response => {
        if (response.code === 200) {
          this.getList()
          this.dialogFormVisible = false;
          this.$notify({
            type: 'success',
            message: '操作成功',
            position: 'bottom-right',
            showClose: false,
            duration: 3000
          });
        } else {
          this.$message({
            message: response.message,
            type: 'error'
          });
        }
      })
    },
    getList() {
      this.listLoading = true;
      let urlData = "?";
      if (this.listQuery.page) {
        urlData = urlData + `page=${this.listQuery.page}&`;
      }
      if (this.listQuery.perPage) {
        urlData = urlData + `perPage=${this.listQuery.perPage}`;
      }
      if (this.listQuery.id) {
        urlData = urlData + `&id=${this.listQuery.id}`;
      }
      if (this.listQuery.name) {
        urlData = urlData + `&name=${this.listQuery.name}`;
      }
      listData(urlData).then((response) => {

        this.menuList = response.data.data;
        this.total = response.data.total;
        this.listLoading = false
      })
    },
    getTypeData() {
      typeData(`?page=1&perPage=100000`).then(res => {
        // res)
        res.data.data.forEach(item => {
          this.typeOptions.push({ value: item.id, label: item.name })
        })
      })
    },
    getTypeList() {
      listTypeData().then(response => {
        response.data.gift.forEach(item => {
          this.giftType.push({ value: item.id, label: item.name })
        })
        response.data.ride.forEach(item => {
          this.mountType.push({ value: item.id, label: item.title })
        })
        response.data.head.forEach(item => {
          this.pendantType.push({ value: item.id, label: item.title })
        })
      })
    },
    getSpecialList() {
      let obj = {
        page: 1,
        perPage: 100000,
        category_id: 4
      }
      listSpecialData(obj).then(response => {
        // response)
        response.data.list.forEach(item => {
          this.specialType.push({ value: item.id, label: item.title })
        })
      })
    },
    getPropList() {
      listPropData(`?page=1&perPage=10000&type=0`).then(response => {
        response.data.data.forEach(item => {
          this.propItemType.push({ value: item.id, label: item.name })
        })
      })
    },
    searchSubmit() {
      this.listQuery.page = 1;
      this.getList()
    },
    resetSubmit() {
      this.listQuery.page = 1;
      this.listQuery.perPage = 10
      this.listQuery.id = undefined;
      this.listQuery.name = undefined;
    },
    // 点击新增
    handleCreate() {
      this.resetForm('editRulesForm')
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
    },
    addGift() {
      this.giftArr.push({
        item_id: undefined,
        type: 6,
        number: undefined,
        weight: undefined,
      });
    },
    addMount() {
      this.mountArr.push({
        item_id: undefined,
        type: 3,
        number: undefined,
        weight: undefined,
      });
    },
    addPendant() {
      this.pendantArr.push({
        item_id: undefined,
        type: 2,
        number: undefined,
        weight: undefined,
      });
    },
    addSpecial() {
      this.specialArr.push({
        item_id: undefined,
        type: 4,
        number: undefined,
        weight: undefined,
      });
    },
    addProp() {
      this.propArr.push({
        item_id: undefined,
        type: 8,
        number: undefined,
        weight: undefined,
      });
    },
    removeGift(item) {
      let index = this.giftArr.indexOf(item)
      if (index !== -1) {
        this.giftArr.splice(index, 1)
      }
    },
    removeMount(item) {
      let index = this.mountArr.indexOf(item)
      if (index !== -1) {
        this.mountArr.splice(index, 1)
      }
    },
    removePendant(item) {
      let index = this.pendantArr.indexOf(item)
      if (index !== -1) {
        this.pendantArr.splice(index, 1)
      }
    },
    removeSpecial(item) {
      let index = this.specialArr.indexOf(item)
      if (index !== -1) {
        this.specialArr.splice(index, 1)
      }
    },
    removeProp(item) {
      let index = this.propArr.indexOf(item)
      if (index !== -1) {
        this.propArr.splice(index, 1)
      }
    },
    // 点击编辑
    handleUpdate(row) {

      this.row_id = row.id
      this.editRulesForm.propType = row.type
      this.giftArr = [];
      this.mountArr = [];
      this.pendantArr = [];
      this.specialArr = [];
      this.propArr = [];
      this.editRulesForm.id = row.id
      this.editRulesForm.name = row.name;
      this.editRulesForm.picture = row.picture
      this.propPictureList = [{ url: row.picture }]
      this.editRulesForm.remark = row.remark

      row.reward_detail.forEach(item => {
        if (item.type === 8) {
          let obj = {}
          obj.item_id = item.item_id;
          obj.type = item.type;
          obj.number = item.number;
          if (item.weight !== 0) {
            obj.weight = item.weight
          }
          this.propArr.push(obj);
        } else if (item.type === 6) {
          let obj = {}
          obj.item_id = item.item_id;
          obj.type = item.type;
          obj.number = item.number;
          if (item.weight !== 0) {
            obj.weight = item.weight
          }
          this.giftArr.push(obj);
        } else if (item.type === 3) {
          let obj = {}
          obj.item_id = item.item_id;
          obj.type = item.type;
          obj.number = item.number;
          if (item.weight !== 0) {
            obj.weight = item.weight
          }
          this.mountArr.push(item);
        } else if (item.type === 2) {
          let obj = {}
          obj.item_id = item.item_id;
          obj.type = item.type;
          obj.number = item.number;
          if (item.weight !== 0) {
            obj.weight = item.weight
          }
          this.pendantArr.push(item)
        } else if (item.type === 4) {
          let obj = {}
          obj.item_id = item.item_id;
          obj.type = item.type;
          obj.number = item.number;
          if (item.weight !== 0) {
            obj.weight = item.weight
          }
          this.specialArr.push(item)
        }
      })
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
    },
    // 重置表单内容
    resetForm(formName) {
      this.$nextTick(() => {
        // this.$refs[formName].resetFields();
        if (this.$refs[formName] !== undefined) {
          this.$refs[formName].resetFields();
        }
        this.cityList = [];
        this.editRulesForm = {
          name: undefined,
          propType: 1,
          remark: undefined,
          picture: undefined,
        }
        this.giftArr = []
        this.mountArr = []
        this.pendantArr = []
        this.specialArr = []
        this.propArr = []
        this.propPictureList = []
      })

    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.dialogStatus === 'create') {
            let obj = {};
            obj['id'] = 0;
            obj['op_type'] = 1
            obj['type'] = this.editRulesForm.propType
            obj['name'] = this.editRulesForm.name
            obj['remark'] = this.editRulesForm.remark
            obj['picture'] = this.editRulesForm.picture
            obj['products'] = []
            if (this.giftArr.length !== 0) {
              this.giftArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.mountArr.length !== 0) {
              this.mountArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.pendantArr.length !== 0) {
              this.pendantArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.specialArr.length !== 0) {
              this.specialArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.propArr.length !== 0) {
              this.propArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            putData(obj).then(response => {
              if (response.code === 200) {
                this.getList()
                this.dialogFormVisible = false;
                this.$notify({
                  type: 'success',
                  message: '操作成功',
                  position: 'bottom-right',
                  showClose: false,
                  duration: 3000
                });
              } else {
                this.$message({
                  message: response.message,
                  type: 'error'
                });
              }
            })
          } else {
            let obj = {};
            obj['id'] = this.row_id;
            obj['op_type'] = 2
            obj['type'] = this.editRulesForm.propType
            obj['name'] = this.editRulesForm.name
            obj['remark'] = this.editRulesForm.remark
            obj['picture'] = this.editRulesForm.picture
            obj['products'] = []
            if (this.propArr.length !== 0) {
              this.propArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.giftArr.length !== 0) {
              this.giftArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.mountArr.length !== 0) {
              this.mountArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.pendantArr.length !== 0) {
              this.pendantArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            if (this.specialArr.length !== 0) {
              this.specialArr.forEach(item => {
                let itemObj = {}
                for (let key in item) {
                  if (item[key] != undefined) {
                    itemObj[key] = item[key]
                  }
                }
                obj['products'].push(itemObj)
              })
            }
            putData(obj).then(response => {
              if (response.code === 200) {
                this.getList()
                this.dialogFormVisible = false;
                this.$notify({
                  type: 'success',
                  message: '操作成功',
                  position: 'bottom-right',
                  showClose: false,
                  duration: 3000
                });
              } else {
                this.$message({
                  message: response.message,
                  type: 'error'
                });
              }
            })
          }
        } else {

          return false;
        }
      });
    },
    handleGive(row) {
      this.row_id = row.id
      this.giveForm.user_codes = undefined
      this.giveForm.name = row.name;
      this.giveFormVisible = true;
    },
    giveSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let obj = {}
          obj.user_codes = this.giveForm.user_codes
          obj.id = this.row_id
          putSendData(obj).then(response => {
            if (response.code === 200) {
              this.getList()
              this.giveFormVisible = false;
              this.$notify({
                type: 'success',
                message: '操作成功',
                position: 'bottom-right',
                showClose: false,
                duration: 3000
              });
            } else {
              this.$message({
                message: response.message,
                type: 'error'
              });
            }
          })
        } else {

          return false;
        }
      });
    },
    // 勾选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 点击单个删除
    handleDelete(row) {
      this.row_id = row.id
      // this.dataIds = {ids:`${row.id}`}
      this.deleteDialogVisible = true
    },
    // 点击批量删除
    handleDeleteAll() {
      if (this.multipleSelection.length === 0) {
        this.$message({
          message: '请先勾选要删除的内容',
          type: 'warning'
        });
        return;
      } else if (this.multipleSelection.length !== 0) {
        let ids = '';
        for (let key in this.multipleSelection) {
          ids += `${this.multipleSelection[key].id},`
        }
        ids = ids.substring(0, ids.length - 1)
        this.dataIds = { ids: ids }
      }
      this.deleteDialogVisible = true
    },
    // 确定删除
    confirmDelete() {
      let obj = { op_type: 0, id: this.row_id }
      putData(obj).then((response) => {
        if (response.code === 200) {
          this.getList()
          this.deleteDialogVisible = false;
          this.$notify({
            type: 'success',
            message: '操作成功',
            position: 'bottom-right',
            showClose: false,
            duration: 3000
          });
        } else {
          this.$message({
            message: response.message,
            type: 'error'
          });
        }
      })
    },
  }
}
</script>

<style scoped>
[v-cloak] {
  display : none;
}

.clearfix:before,
.clearfix:after {
  display : table;
  content : "";
}

.clearfix:after {
  clear : both
}

.box-card {
  width : 100%;
}

.demo-form-inline {
  float : right;
}

.el-table .tagDiv {
  display : block;
}


/deep/ .el-table_1_column_6 .cell > div {
  margin-bottom : 10px;
}

/deep/ .el-upload-list__item {
  transition : none !important;
}

/deep/ .el-card__header {
  padding-bottom : 0;
}

/* .avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409EFF;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
} */
</style>
